package com.yupi.springbootinit.rpc.IMPL;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jun.apiplatformcommon.entity.InterfaceInfo;
import com.jun.apiplatformcommon.service.InnerInterfaceInfoService;
import com.yupi.springbootinit.common.ErrorCode;
import com.yupi.springbootinit.exception.BusinessException;
import com.yupi.springbootinit.mapper.InterfaceInfoMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;

import javax.annotation.Resource;

@DubboService
public class InnerInterfaceInfoServiceImpl implements InnerInterfaceInfoService {

	@Resource
	private InterfaceInfoMapper interfaceInfoMapper;

	@Override
	public InterfaceInfo getInvokeInterfaceInfo(String url, String method) {
		if (StrUtil.hasBlank(url, method)) {
			throw new BusinessException(ErrorCode.PARAMS_ERROR);
		}

		LambdaQueryWrapper<com.yupi.springbootinit.model.entity.InterfaceInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.eq(com.yupi.springbootinit.model.entity.InterfaceInfo::getUrl, url).eq(com.yupi.springbootinit.model.entity.InterfaceInfo::getMethod, method);
		com.yupi.springbootinit.model.entity.InterfaceInfo interfaceInfo = interfaceInfoMapper.selectOne(lambdaQueryWrapper);
		if (interfaceInfo == null) {
			throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
		}
		InterfaceInfo interfaceInfo1 = new InterfaceInfo();
		BeanUtils.copyProperties(interfaceInfo, interfaceInfo1);
		return interfaceInfo1;
	}

}